<?php
class Admin_Acl_Role_Update_Action extends NICED_Action 
{       
	public function execute() 
	{
        $this->forward("admin.index");

		$controller = $this->getController();
		$request    = $controller->getRequest();			
        $id         = $request->loadParam("id", NULL, "posint");
        $name       = $request->loadParam("name", NULL, "safe");
        $access_ids = $request->loadParam("access_ids", NULL);
        $act  = $request->loadParam("act", NULL, "safe");

        //if not have id ,load from uri
        if (!$id)
        {
            $id = $request->loadArg(0, "id", 0, "posint");
        }

        if (!$id)
        {
            throw new Exception("please assign id");
        }

		$model = $controller->getModel('Admin.Acl.Role.Index');
        $model->getById($id);

        //if no act param, show create page
        if (!$act)
        {
            return self::SUCCESS;
        }

		try
		{
            $model->update($id, $name, $access_ids);
		}
		catch (Exception $e)
		{
			$controller->handleException($e);
			return self::SUCCESS;
		}

		return self::SUCCESS;
	}

}//end class
